package com.sgb.kjwl.viewmodel.pick;

import android.content.Intent;
import android.text.TextUtils;

import com.chuanglan.shanyan_sdk.OneKeyLoginManager;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.LoginEntity;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.pick.TenderAllListEntity;
import com.sgb.kjwl.model.entity.user.OneKeyLoginEntity;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickInquireByLetterActivity;
import com.sgb.kjwl.view.ui.activity.pick.ReportActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.SetPwdActivity;
import com.sgb.kjwl.view.ui.fragment.pick.PickHallAllFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.dialog.DialogHelper;
import com.im.immodel.IMUtils;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.view.areapopup.AddressEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.jpush.android.api.JPushInterface;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PickHallAllFragmentModel extends BaseViewModel {

    private PickHallAllFragment fragment;
    private HomeRepertory repertory;
    private int pageSize = 10;
    private int page = 1;
    public int total;
    private String longitude;
    private String latitude;
    private PickSelectEntity mAll;

    public PickHallAllFragmentModel(PickHallAllFragment fragment, HomeRepertory repertory) {
        this.fragment = fragment;
        this.repertory = repertory;
        mAll = new PickSelectEntity();
        mAll.setNo("");
        mAll.setProjectscale("全部");
    }

    //招标大厅-全部
    public void findTenderingHomeEsPage(String type, String goodsType, String areacode, String city, String keyword, boolean isLoadMore, String comNo) {

        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "获取信息中...", 0, false, null, false);
        Map map = new HashMap();
        page = isLoadMore ? page + 1 : 1;
        map.put("current", page);
        map.put("limit", pageSize);
        if ("0".equals(type)) {
            type = "";
        }
        map.put("type", type);
        map.put("goodsTypeNo", goodsType);
        map.put("province", areacode);
        map.put("city", city);
        map.put("keyword", keyword);
        map.put("comNo", comNo);

        APIManager.getInstance().getPickAPI().findTenderingHomeEsPage(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<TenderAllListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<TenderAllListEntity>>> data) {
                if (data == null) return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.getAllData(data.getData().getList());
                }
            }
        });
    }

    //招标大厅-全部地图
    public void findTenderingHomeEsPageMap(String type, String goodsType, String areacode, String city, String keyword, boolean isLoadMore, String comNo, String distance, double latitude, double longitude) {

        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "获取信息中...", 0, false, null, false);
        Map map = new HashMap();
        page = isLoadMore ? page + 1 : 1;
        map.put("current", page);
        map.put("limit", pageSize);
        if ("0".equals(type)) {
            type = "";
        }
        map.put("type", type);
        map.put("goodsTypeNo", goodsType);
        map.put("province", areacode);
        map.put("city", city);
        map.put("keyword", keyword);
        map.put("comNo", comNo);
        map.put("distance", distance);
        map.put("longitude", longitude);
        map.put("latitude", latitude);

        APIManager.getInstance().getPickAPI().findTenderingHomeEsPageMap(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<TenderAllListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<TenderAllListEntity>>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.showMapList(data.getData().getList(), data.getData().isLastPage(), isLoadMore);
                    fragment.setbiddingListEntityMapList(data.getData().getList(), isLoadMore, page);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    //招标公告-全部
    public void findNoticeHomeEsPage(String type, String goodsType, String areacode, String city, String keyword, boolean isLoadMore) {

        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "获取信息中...", 0, false, null, false);
        Map map = new HashMap();
        page = isLoadMore ? page + 1 : 1;
        map.put("current", page);
        map.put("limit", pageSize);
        if ("0".equals(type)) {
            type = "";
        }
        map.put("type", type);
        map.put("goodsTypeNo", goodsType);
        map.put("province", areacode);
        map.put("city", city);
        map.put("keyword", keyword);

        APIManager.getInstance().getPickAPI().findNoticeHomeEsPage(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<TenderAllListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<TenderAllListEntity>>> data) {
                if (data == null) return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.getAllData(data.getData().getList());
                }
            }
        });
    }

    //招标公告-全部地图
    public void findNoticeHomeEsPageMap(String type, String goodsType, String areacode, String city, String keyword, boolean isLoadMore, String distance, double latitude, double longitude) {

        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "获取信息中...", 0, false, null, false);
        Map map = new HashMap();
        page = isLoadMore ? page + 1 : 1;
        map.put("current", page);
        map.put("limit", pageSize);
        if ("0".equals(type)) {
            type = "";
        }
        map.put("type", type);
        map.put("goodsTypeNo", goodsType);
        map.put("province", areacode);
        map.put("city", city);
        map.put("keyword", keyword);
        map.put("distance", distance);
        map.put("longitude", longitude);
        map.put("latitude", latitude);

        APIManager.getInstance().getPickAPI().findNoticeHomeEsPageMap(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<TenderAllListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<TenderAllListEntity>>> data) {
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (data == null || data.getState() == null) {
                        return;
                    }
                    if (data.getState().equals(APIManager.RESPONSE_OK)) {
                        fragment.showMapList(data.getData().getList(), data.getData().isLastPage(), isLoadMore);
                        fragment.setbiddingListEntityMapList(data.getData().getList(), isLoadMore, page);
                    } else {
                        MToast.showToast(fragment.getActivity(), data.getMsg());
                    }
                }
            }
        });
    }

    public void getProvinceData(int type) {
        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "加载中", 0, true, null, false);
        APIManager.getInstance().getPickAPI().getAddressEntityCityList().enqueue(new ICallBack<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>>() {
            @Override
            public void onSuccess(BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>> data) {
                if (data != null && data.getData() != null && data.getData().size() > 0) {
                    List<PickSelectEntity> entities = new ArrayList<>();
                    for (AddressEntity<List<AddressEntity<List<AddressEntity>>>> datum : data.getData()) {
                        entities.add(new PickSelectEntity(datum.getNo(), datum.getSimpleName()));
                    }
                    entities.add(0, mAll);
                    fragment.setChooseItemData(type, entities);
                    fragment.setProvinceDatas(data.getData());
                }
            }
        });
    }

    public void getAddressCityData(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> scrData, String no, int type) {
        for (AddressEntity<List<AddressEntity<List<AddressEntity>>>> scrDatum : scrData) {
            if (scrDatum.getId().equals(no)) {
                List<AddressEntity<List<AddressEntity>>> children = scrDatum.getChildren();
                if (children != null && children.size() > 0) {
                    List<PickSelectEntity> entities = new ArrayList<>();
                    for (AddressEntity<List<AddressEntity>> child : children) {
                        entities.add(new PickSelectEntity(child.getNo(), child.getSimpleName()));
                    }
                    entities.add(0, mAll);
                    fragment.setChooseItemData(type, entities);
                }
            }
        }
    }

    public void getAddressCityDataDialog(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> scrData, String no) {
        for (AddressEntity<List<AddressEntity<List<AddressEntity>>>> scrDatum : scrData) {
            if (scrDatum.getId().equals(no)) {
                List<AddressEntity<List<AddressEntity>>> children = scrDatum.getChildren();
                if (children != null && children.size() > 0) {
                    List<PickSelectEntity> entities = new ArrayList<>();
                    for (AddressEntity<List<AddressEntity>> child : children) {
                        entities.add(new PickSelectEntity(child.getNo(), child.getSimpleName()));
                    }
                    entities.add(0, mAll);
                    fragment.setCityDatas(entities);
                }
            }
        }
    }

    //新增类型过滤接口
    public void getTenderGoodsCategoryAllList(String category) {
        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "加载中", 0, true, null, false);
        Map map = new HashMap();
        map.put("type", category);
        APIManager.getInstance().getPickAPI().getTenderGoodsCategoryAllList(map).enqueue(new Callback<BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>>> call, Response<BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.setTenderGoodsCategoryAllList(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getFilterTypeData() {
        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "加载中", 0, true, null, false);
        APIManager.getInstance().getPickAPI().tenderNewTypeList().enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.setTypeDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getUrlSetting(String id) {
        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "加载中", 0, true, null, false);
        APIManager.getInstance().getPickAPI().getUrlSetting("competitivePurchase").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
                    String lng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
                    String lat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
                    url = url + "&lng=" + lng + "&lat=" + lat;
                    MLog.d("api", "H5跳转链接  " + url);
                    fragment.getUrl(url, id);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void getWebH5(String id, String moduleType) {
        longitude = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
        latitude = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
        if (TextUtils.isEmpty(longitude)) {
            longitude = "0";
        }
        if (TextUtils.isEmpty(latitude)) {
            latitude = "0";
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("demandNoticeDetails").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String webUrl = data.getData().getUrl() + "?id=" + id + "&localLat=" + latitude + "&localLng=" + longitude + "&type=" + moduleType;
                    WebViewX5HostActivity.start(fragment.getActivity(), webUrl);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void getUrlSettingTender(String id) {
        DialogHelper.showProgressDialog2(fragment.getActivity(), null, "加载中", 0, true, null, false);
        APIManager.getInstance().getPickAPI().getUrlSetting("FrontDeskBidding").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
                    String lng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
                    String lat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
                    url = url + "&lng=" + lng + "&lat=" + lat;
                    MLog.d("api", "H5跳转链接  " + url);
                    fragment.getUrl(url, id);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void findCustomerServiceImAccount(String customerServiceContactsId) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("customerServiceContactsId", customerServiceContactsId);
        APIManager.getInstance().getPickAPI().getfindCustomerServiceImAccount(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
                    fragment.checkAllowDialog(response.body().getMsg());
                } else {
                    String dataIMid = response.body().getData().toString();
                    IMUtils.getInstance().buildSingleTalking(dataIMid);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    public void checkAllowBidQuestion(String bidNo, int bidType) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("bidNo", bidNo);
        APIManager.getInstance().getPickAPI().checkAllowBidQuestion(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
                    fragment.checkAllowDialog(response.body().getMsg());

                } else {
                    PickInquireByLetterActivity.start(fragment.getActivity(), bidNo, "jj", bidType);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void checkAllowTenderQuestion(String tenderNo, int tenderingType) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("tenderNo", tenderNo);
        APIManager.getInstance().getPickAPI().checkAllowTenderQuestion(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
                    fragment.checkAllowDialog(response.body().getMsg());
                } else {
                    PickInquireByLetterActivity.start(fragment.getActivity(), tenderNo, "activity", tenderingType);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    public void editTender(String tenderNo, int position) {
        Map map = new HashMap();
        map.put("tenderNo", tenderNo);
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().editTender(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.setTvIsGz(position);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void editBid(String bidNo, int position) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("bidNo", bidNo);
        APIManager.getInstance().getPickAPI().editBid(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.setTvIsGz(position);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void countByBusiness(String businessNo, int businessType) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("businessNo", businessNo);
        map.put("businessType", businessType);
        APIManager.getInstance().getPickAPI().countByBusiness(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if(!"可进行举报监督操作".equals(response.body().getData())){
                        fragment.checkAllowDialog(response.body().getData().toString());
                    }else{
                        if (businessType == 1) {
                            ReportActivity.start(fragment.getActivity(), businessNo, "1");
                        } else if (businessType == 2) {
                            ReportActivity.start(fragment.getActivity(), businessNo, "2");
                        }
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void oneKeyLogin(OneKeyLoginEntity oneKeyLoginEntity) {
        DialogHelper.showProgressDialog(fragment.getContext(), null, "登录中", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getUserAPI().oneClickLogin(oneKeyLoginEntity).enqueue(new Callback<BaseEntity<LoginEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<LoginEntity>> call, Response<BaseEntity<LoginEntity>> response) {

                DialogHelper.dismissProgressDialog();
                if (response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    OneKeyLoginManager.getInstance().finishAuthActivity();
                    if (response.body().getData().isNeedRegister()) {
                        Intent intent = new Intent(fragment.getContext(), SetPwdActivity.class);
                        intent.putExtra("mobile", response.body().getData().getPhone());
                        fragment.startActivity(intent);
                    } else {
                        //登录成功逻辑
                        loginImModel(response);

                        /*saveUserInfo(response.body().getData());
                        activity.loginSucceed(response.body().getData(), response.body().getData().getPhone());
                        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_TOKEN, response.body().getData().getToken());
                        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_PHONE, response.body().getData().getPhone());
                        JPushInterface.setAlias(activity, 1, response.body().getData().getPhone());
                        getUserInfo();*/
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<LoginEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    //网易IM登陆
    private void loginImModel(Response<BaseEntity<LoginEntity>> response) {
//        NimUIKit.login(new LoginInfo(response.body().getData().getImAccount(), response.body().getData().getImToken()), new RequestCallback<LoginInfo>() {
//            @Override
//            public void onSuccess(LoginInfo param) {
                DialogHelper.dismissProgressDialog();
                SharedPreferenceUtil.getInstance().cleatData();
                saveUserInfo(response.body().getData());
                MToast.showToast(fragment.getContext(), "登录成功");
                fragment.loginSucceed(response.body().getData(), response.body().getData().getPhone());
                SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_TOKEN, response.body().getData().getToken());
                SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_PHONE, response.body().getData().getPhone());
                JPushInterface.setAlias(fragment.getContext(), 1, response.body().getData().getPhone());
                getUserInfo();
//            }
//
//            @Override
//            public void onFailed(int code) {
//                DialogHelper.dismissProgressDialog();
//            }
//
//            @Override
//            public void onException(Throwable exception) {
//                DialogHelper.dismissProgressDialog();
//            }
//        });
    }

    public void getUserInfo() {
        DialogHelper.showProgressDialog(fragment.getContext(), null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getUserAPI().getUserInfo().enqueue(new Callback<BaseEntity<UserMsgEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<UserMsgEntity>> call, Response<BaseEntity<UserMsgEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getData() == null) return;
                if (response.body().getState().equals("ok")) {
                    fragment.getUserMsgSucceed(response.body().getData());
                } else {
                    MToast.showToast(fragment.getContext(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<UserMsgEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    private void saveUserInfo(LoginEntity loginEntity) {
        repertory.saveToken(loginEntity.getToken());
        repertory.saveAccount(loginEntity.getPhone());
    }
}
